"use strict";

/**
 * author:Administrator
 * date:2015/11/30
 * desc: user face dao
 */
var Model = require('../model/face_part.js');
var dao = {};

module.exports = dao;

/**
 * save
 * json uid,path
 */
dao.save = function *(json) {
  var entity = new Model({
    partid: json.partid,
    otype: json.otype,
    starid: json.starid,
    path: json.path,
    desc: json.desc || '',
    rurl: json.rurl
  });

  return yield entity.save();
};

dao.getAll = function*() {
  return yield Model.find();
};

dao.getByPartids = function *(partidArr) {
  return yield Model.find({partid: {$in: partidArr}});
};

dao.getByStaridAndOtype = function*(starid, otype) {
  return yield Model.findOne({starid: starid, otype: otype});
};

dao.getByPartid = function *(partid) {
  return yield Model.findOne({partid: partid});
};

dao.getByStarid = function*(starid) {
  return yield Model.find({starid: starid});
};

dao.cleanCollection = function*() {
  return yield Model.remove({});
};

dao.update = function * (json) {
  return yield Model.update(json.query, json.update);
};